<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>

    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{lib/css/main.css}">
    <link rel="stylesheet" th:href="@{/lib/css/public.css}">

    <script th:src="@{/lib/js/jquery-3.4.1.min.js}"></script>
    <!--<script th:src="@{/layui/layui.js}"></script>-->
    <!--<script th:src="@{/lib/js/allclass.js}"></script>-->



</head>




<body>

<div class="table">
    <h2 class="tablename">购买套餐</h2>
    <hr class="layui-bg-gray">
    <table class="layui-hide" id="demo" lay-filter="test"></table>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">

                            <!--<div class="layui-inline layui-show-xs-block">-->
                                <!--<input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">-->
                            <!--</div>-->
                            <!--<div class="layui-inline layui-show-xs-block">-->
                                <!--<input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">-->
                            <!--</div>-->
                            <!--<div class="layui-inline layui-show-xs-block">-->
                                <!--<input type="text" name="username"  id="studentname" th:value="${name}" placeholder="请输入饲养师姓名" autocomplete="off" class="layui-input">-->
                            <!--</div>-->
                            <div class="layui-inline layui-show-xs-block">
                                <a class="layui-btn" href="/saisinglist">返回</a>
                            </div>

                    </div>
                    <!--<div class="layui-card-header">-->
                        <!--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
                        <!--<button class="layui-btn" onclick="xadmin.open('添加用户','./admin-add.html',600,400)"><i class="layui-icon"></i>添加</button>-->
                    <!--</div>-->
                    <div class="layui-card-body ">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>请选择饲养时间</th>
                                <!--<th>宠物等级</th>-->
                                <th>洗澡次数</th>
                                <th>宠物兜圈次数</th>
                                <th>拓展</th>
                                <th>备注</th>
                                <th>操作</th>
                            </thead>
                            <tbody>
                            <div th:each="j:${list.list}">
                            <tr>

                                <td> 从  <input type="date" class="begintime" th:id="${j.id}+begin"/>开始寄养，
                                    到<input type="date" class="endtime" th:id="${j.id}+end"/>结束饲养</td>
                                <!--<td> <select>-->
                                    <!--<option value ="volvo">Volvo</option>-->
                                    <!--<option value ="saab">Saab</option>-->
                                    <!--<option value ="audi">Audi</option>-->
                                <!--</select> </td>-->
                                <td ><input type="text" name="stuAge" th:id="${j.id}+xizao" required class="layui-input stuAge"></td>
                                <td><input type="text" name="stuIdCard" th:id="${j.id}+douqvan" required class="layui-input stuIdCard"></td>
                                <td th:text="${j.tuozhan}">超级管理员</td>
                                <td><input type="text" name="stuIdCard" th:id="${j.id}+beizhu" placeholder="选填" required class="layui-input stuIdCard"></td>
                                <!--<td class="td-status">-->
                                    <!--<span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>-->
                                <td class="td-manage">
                                  <!--从  <input type="date" class="begintime" th:id="${j.id}+begin"/>开始寄养，-->
                                    <!--到<input type="date" class="endtime" th:id="${j.id}+end"/>结束饲养-->
                                   <button type="button" th:onclick="|javascript:siyang('${j.id}')|" class="layui-btn layui-btn-normal layui-btn-radius">购买并寄养</button>
                                    <button type="button" th:onclick="|javascript:pingjia('${j.id}')|" class="layui-btn layui-btn-normal layui-btn-radius">查看评价</button>
                                    <!--<a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">-->
                                        <!--<i class="layui-icon">&#xe601;</i>-->
                                    <!--</a>-->
                                    <!--<a title="编辑"  onclick="xadmin.open('编辑','admin-edit.html')" href="javascript:;">-->
                                        <!--<i class="layui-icon">&#xe642;</i>-->
                                    <!--</a>-->
                                    <!--<a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">-->
                                        <!--<i class="layui-icon">&#xe640;</i>-->
                                    <!--</a>-->
                                </td>
                            </tr>
                            </div>
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            <div>
                                当前页: [[${list.pageNum}]] 总页数：[[${list.pages}]] 总条数：[[${list.total}]] <a class="layui-btn layui-btn-normal layui-btn-radius" href="#" onclick="index()">首页</a>    <a href="#" class="layui-btn layui-btn-normal layui-btn-radius" onclick="shangyiye()">上一页</a> <a class="layui-btn layui-btn-normal layui-btn-radius" id="pagenext"  href="#" onclick="xiayiye()" >下一页</a> <a class="layui-btn layui-btn-normal layui-btn-radius" href="#" onclick="wenye()">尾页</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    //首页
    function index(){
        var rId = [[${rId}]]
        //首页
        var pageNum= 1;
        location.href="/gmtaocan?pageNum="+pageNum+"&rId="+rId;
    }

    //上一页
    function shangyiye(){

        //上一页
        var  shangy =  [[${list.prePage}]]

        location.href="/gmtaocan?pageNum="+shangy+"&rId="+rId;
    }

    //下一页
    function xiayiye(){

        var pageNum = [[${list.pageNum}]]

        var info = [[${list.pages}]]
        //当前页等于总条数的时候就是最后一页！
        if(pageNum == info){
            alert("亲，已经是最后一页了！")
            return false;
        }

        //下一页
        var xiay =  [[${list.nextPage}]]
        location.href="/gmtaocan?pageNum="+xiay+"&rId="+rId;
    }

    //尾页
    function wenye(){
        var  name =  $("#studentname").val()
        //  //尾页
        var wenye =  [[${list.pages}]]
        location.href="/gmtaocan?pageNum="+wenye+"&rId="+rId;
    }


    //查看评价
    function pingjia(id){
        location.href="/rpingjia?id="+id;
    }



    //饲养
    function siyang(siyangshiId){



       var begintime= $("#"+siyangshiId+'begin').val()
        var endtime= $("#"+siyangshiId+'end').val()


        if(begintime == ''|| begintime == null){
            alert("请选择开始时间！")
            return false
        }else if(endtime == '' || begintime == null){
            alert("请选择结束时间！")
            return false
        }

        var date1=new Date(begintime);
        var date2=new Date(endtime);

        if(date1 >= date2)
        {
            alert("结束日期不能小于或等于开始日期哦！");
            return false;
        }

        var date=(date2.getTime()-date1.getTime())/(1000*60*60*24);
        //用户输入的洗澡
        var xizao = $("#"+siyangshiId+'xizao').val()
        var douqvan = $("#"+siyangshiId+'douqvan').val()
        var beizhu = $("#"+siyangshiId+'beizhu').val()
        var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
        if(reg.test(douqvan)){
            alert("亲,兜圈次数只输入数字即可！！");
            return false
        }
        if(reg.test(xizao)){
            alert("亲,洗澡次数只输入数字即可！！");
            return false
        }




        $.ajax({
            url:"/userorder",
            type:"POST",
            data:{"id":siyangshiId,"petTake":xizao,"petDate":date,"petNum":douqvan,"beizhu":beizhu},
            success:function (data) {
                if(data == 1){
                    alert("购买成功")
                    $("#"+siyangshiId+'xizao').val('')
                    $("#"+siyangshiId+'douqvan').val('')
                    $("#"+siyangshiId+'beizhu').val('')
                }
            },
            error:function (){
                alert("服务内部故障，请联系技术人员！")
            }
        })


     }

</script>


</body>

</html>